package com.scoresystem.dao.impl;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;

import com.scoresystem.dao.ISubjectDao;
import com.scoresystem.model.Subject;
import com.scoresystem.utils.ResultMapUtil;

public class SubjectDaoImpl extends BaseDaoImpl implements ISubjectDao {
	
	public SubjectDaoImpl(Connection conn){
		super(conn);
		this.conn=conn;
	}
	
	@Override
	public List<Subject> findAll() {
		String sql="select * from subject";
		List<Subject> list=new ArrayList<Subject>();
		try {
			ResultSet rs=templateQuery(sql);
			while(rs.next()){
				Map<String,String> map=ResultMapUtil.getResultMap(rs);				
				Subject sub=new Subject();
				try {
					BeanUtils.populate(sub, map);
				} catch (Exception e) {
					e.printStackTrace();
				} 
				list.add(sub);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}  
        
		return list;
	}

}
